<?php
/**
 * 商品特别推荐专区 
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');
class goods_recomControl extends MobileControl{
	public function __construct(){
		parent::__construct();
	}
	
	public function indexOp(){
		
		//根据买家用户信息所在地区展示在相应地区展示的商品-市级-省级
		if(isset($_SESSION['is_login']) && (int)$_SESSION['is_login'] == 1){
			$member = Model('member')->infoMember(array('member_id'=>(int)$_SESSION['member_id']));
			$area_info = preg_split('/\t/', $member['member_areainfo'],-1,PREG_SPLIT_NO_EMPTY);
			if(count($area_info)==1){
				$province_id = (int)$member['member_provinceid'];
				$where = "AND FIND_IN_SET('$province_id',g.show_in_province_ids)";
			}elseif(count($area_info)==2 || count($area_info)==3){
				$city_id = (int)$member['member_cityid'];
				$where = "AND FIND_IN_SET('$city_id',g.show_in_city_ids)";
			}
		}
		
		$pageSize = 10;
		$curPage = (int)$_GET['curpage'];
		$sql = "SELECT rg.*,g.* FROM #__recommend_goods AS rg LEFT JOIN #__goods AS g ON rg.goods_id = g.goods_id WHERE rg.recommend_id = '1' AND g.goods_state = '0' AND g.goods_show = '1' $where ORDER BY rg.sort ASC,rg.goods_id DESC";
		$rs = Db::PageQuery($sql,$curPage,$pageSize);
		$list = $rs->fetchAll();
		
		//分页
		$page	= new Page();
		$page->setEachNum($pageSize);
		$page->setNowPage($curPage);
		$page->setTotalNum($rs->pageRows());
		$page->setStyle('admin');
		
		if($_GET['type'] == 'ajax'){
			echo json_encode($list);
			exit;
		}else{
			Tpl::output('totalPage',ceil($rs->pageRows()/$pageSize));
			Tpl::output('list',$list);
			Tpl::showpage('goods_recom');
		}
	}
}